package com.example.lj.uav.view;

import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;

import com.example.lj.uav.R;
import com.example.lj.uav.view.base.BaseActivity;
import com.example.lj.uav.widget.CommomDialog;

import static com.example.lj.uav.MyApplication.mPref;

public class PrivacyActivity extends BaseActivity implements View.OnClickListener {

    private CheckBox cb1;
    private CheckBox cb2;
    private CheckBox cb3;
    private CheckBox cb4;
    private LinearLayout text_1;
    private LinearLayout text_2;
    private LinearLayout text_3;
    private LinearLayout text_4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_privacy);
        findViewById(R.id.privacy_fl_back).setOnClickListener(this);
        findViewById(R.id.privacy_cb_hide_1).setOnClickListener(this);
        findViewById(R.id.privacy_cb_hide_2).setOnClickListener(this);
        findViewById(R.id.privacy_cb_hide_3).setOnClickListener(this);
        findViewById(R.id.privacy_cb_hide_4).setOnClickListener(this);
        cb1 = findViewById(R.id.privacy_cb_choice_1);
        cb1.setOnClickListener(this);
        cb2 = findViewById(R.id.privacy_cb_choice_2);
        cb2.setOnClickListener(this);
        cb3 = findViewById(R.id.privacy_cb_choice_3);
        cb3.setOnClickListener(this);
        cb4 = findViewById(R.id.privacy_cb_choice_4);
        cb4.setOnClickListener(this);
        cb1.setChecked(mPref.getBoolean("mobile_gps", false));
        cb2.setChecked(mPref.getBoolean("dji_gps", false));
        cb3.setChecked(mPref.getBoolean("dji_hardware", false));
        cb4.setChecked(mPref.getBoolean("dji_fuzzy_position", false));
        text_1 = findViewById(R.id.privacy_ll_text_1);
        text_2 = findViewById(R.id.privacy_ll_text_2);
        text_3 = findViewById(R.id.privacy_ll_text_3);
        text_4 = findViewById(R.id.privacy_ll_text_4);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.privacy_fl_back:
                finish();
                break;
            case R.id.privacy_cb_hide_1:
                if (text_1.getVisibility() == View.VISIBLE)
                    text_1.setVisibility(View.GONE);
                else
                    text_1.setVisibility(View.VISIBLE);
                break;
            case R.id.privacy_cb_hide_2:
                if (text_2.getVisibility() == View.VISIBLE)
                    text_2.setVisibility(View.GONE);
                else
                    text_2.setVisibility(View.VISIBLE);
                break;
            case R.id.privacy_cb_hide_3:
                if (text_3.getVisibility() == View.VISIBLE)
                    text_3.setVisibility(View.GONE);
                else
                    text_3.setVisibility(View.VISIBLE);
                break;
            case R.id.privacy_cb_hide_4:
                if (text_4.getVisibility() == View.VISIBLE)
                    text_4.setVisibility(View.GONE);
                else
                    text_4.setVisibility(View.VISIBLE);
                break;
            case R.id.privacy_cb_choice_1:
                mPref.edit().putBoolean("mobile_gps", cb1.isChecked()).apply();
                break;
            case R.id.privacy_cb_choice_2:
                mPref.edit().putBoolean("dji_gps", cb2.isChecked()).apply();
                break;
            case R.id.privacy_cb_choice_3:
                mPref.edit().putBoolean("dji_hardware", cb3.isChecked()).apply();
                break;
            case R.id.privacy_cb_choice_4:
                if (cb4.isChecked()) {
                    new CommomDialog(this, R.style.commondialog, "该权限为APP整厂运行的必备权限，无法关闭。", new CommomDialog.OnCloseListener() {
                        @Override
                        public void onClick(CommomDialog dialog, boolean confirm) {
                            dialog.dismiss();
                        }
                    }).setTitle("该权限无法关闭").show();
                } else {
                    mPref.edit().putBoolean("dji_fuzzy_position", cb4.isChecked()).apply();
                }
                break;
        }
    }
}
